package com.backtracking;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Solution11 {
    List<List<Integer>> res = new ArrayList<>();


    LinkedList<Integer> tmp = new LinkedList<>();

    public List<List<Integer>> subsets(int[] nums) {
        Arrays.sort(nums);
        backTracking(nums,0);
        res.add(new ArrayList<>());
        return res;
    }


    public void backTracking(int[] nums, int index) {
        if (index >= nums.length) {

            return;
        }

        for (int i = index; i < nums.length; i++) {
            tmp.add(nums[i]);
            res.add(new ArrayList<>(tmp));
            backTracking(nums,i+1);
            tmp.removeLast();
        }
    }
}
